package com.framework.modules.base.dao;

import com.framework.modules.base.entity.ValidateCodeEntity;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 系统验证码表 存储手机或其他的验证信息
 * 
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-10-12 10:45:15
 */
public interface ValidateCodeDao extends BaseMapper<ValidateCodeEntity> {

    /**
     * 检查某手机号最新的验证码是否能够使用
     * @param mobile
     * @param exprirdTimeStamp
     * @return
     */
    @Select("select * from tb_validate_code where mob=#{mobile} and state=0 and adddate > #{exprirdTimeStamp} order by id desc limit 0,1")
    ValidateCodeEntity getLastValidCodeEntry(@Param("mobile") String mobile,@Param("exprirdTimeStamp") Integer exprirdTimeStamp);


    /**
     * 检查指定时间戳区间范围内的短信发送数量
     * @param mobile
     * @param start
     * @param end
     * @return
     */
    @Select("select count(1) from tb_validate_code a where a.mob=#{mobile} and state=0 and a.adddate between #{start} and #{end}")
    Integer checkCodeCount(@Param("mobile") String mobile,@Param("start") Integer start,@Param("end") Integer end);

    /**
     * 更新短信状态
     * @param id
     * @param state
     * @return
     */
    @Update("update tb_validate_code set state=#{state} where id=#{id}")
    Integer updateState(@Param("id") Integer id,@Param("state") Integer state);




}
